package cn.com.cifi.mars.util;


import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;


public class ListUtils {

    public static List<String> groupNameList = Arrays.asList("一组团", "二组团", "三组团", "四组团", "五组团", "六组团", "七组团", "八组团", "九组团", "十组团", "十一组团", "十二组团", "十三组团", "十四组团", "十五组团", "十六组团", "十七组团", "十八组团", "十九组团", "二十组团","车位组团");

    public static List<String> stageNameList = Arrays.asList("一期", "二期", "三期", "四期", "五期", "六期", "七期", "八期", "九期", "十期", "十一期", "十二期", "十三期", "十四期", "十五期", "十六期", "十七期", "十八期", "十九期", "二十期");



    public static List<List> getSubList(List list, int len) {
        if (CollectionUtils.isEmpty(list) || len < 1) {
            return new ArrayList<>();
        }
        List<List> resultList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if ( i % len == 0 ) {
                long count = i/len;
                long limit=(count + 1) * len;
                long skip=count * len;
                List subList = (List) list.stream().limit(limit).skip(skip).collect(Collectors.toList());
                resultList.add(subList);
            }
        }
        return resultList;
    }

    //集合排序
    public static <T, U extends Comparable<? super U>>  List<T> sortByStrList(List<T> list, List<String> nameList, Function<? super T, ? extends U> keyExtractor) {
        Map<String,Integer> map = new HashMap<>();
        int i = 0;
        for (String name : nameList){
            map.put(name,i++);
        }

        list.sort(Comparator.comparing(keyExtractor,(x, y) ->{
            Integer integer1 = map.get(x);
            Integer integer2 = map.get(y);
            return integer1.compareTo(integer2);
        }));
        return list;
    }

}

